import {
  productList
} from "../../../util/api/product.js";
import {
  imgUrl
} from "@/util/api.js";
import {
  getImage
} from "@/util/getImage.js";
export default {
  data() {
    return {
      total: 0,
      list: [],
      params: {
        pageNo: 1,
        pageSize: 15,
        productName: ""
      },
      status: "loadmore",
      companyId: "",
      imgUrl: imgUrl
    };
  },
  onShow() {
    this.getList(1);
  },
  methods: {
    getImageUrl(url) {
      return getImage(url);
    },
    toDetail(id) {
      uni.navigateTo({
        url: `/pages/product/productDetail/Index?id=${id}`
      });
    },
    getList(type) {
      if (type === 1) {
        this.params.pageNo = 1;
      }
      productList(this.params).then(res => {
        if (this.params.pageNo === 1) {
          this.list = res.result.records;
        } else {
          this.list.push(...res.result.records);
        }
        this.total = res.result.total;
      });
    },
    scrolltolower() {
      if (this.list.length >= this.total) {
        return;
      }
      this.params.pageNo = this.params.pageNo + 1;
      this.getList();
    }
  }
};